package com.zyh.controller;


import com.zyh.entity.Message;
import com.zyh.entity.Statistic;
import com.zyh.service.StatisticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@CrossOrigin
public class StatisticController {
    @Autowired
    StatisticService statisticService;

    @GetMapping("/countstatistic")
    @ResponseBody
    public List<Statistic> countstatistic(Statistic statistic) {
        List<Statistic> countstatistic = statisticService.countstatistic(statistic);
//        Map<String, Object> map = new HashMap<>();
//        map.put("data", countstatistic);
//        return map;
        return countstatistic;
    }


    @GetMapping("/selectmessage/{id}")
    @ResponseBody
    public Map<String, Object> selectmessage(@PathVariable("id") Integer userid, Message message) {
        List<Message> selectmesssage = statisticService.selectmesssage(userid);
        Map<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("msg","请求成功");
        map.put("count",1);
        map.put("data",selectmesssage);
        return map;

    }

}
